package com.edu.d4_collection_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ListDemo2 {
    /**
     * list集合：有序、有索引、可重复
     * 遍历方式小结
     */
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("程序员");
        list.add("123");
        list.add("奥特曼");
        list.add("迪迦");
        System.out.println(list+"------------------------");
        /**
         * for循环遍历
         */
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        /**
         * 迭代器遍历
         */
        System.out.println("---------------");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        /**
         * foreach遍历
         */
        System.out.println("------------");
        for (String s : list) {
            System.out.println(s);
        }
        /**
         * Lambda表达式遍历
         */
        System.out.println("-----------------");
        list.forEach(s-> System.out.println(s));
    }
}
